package com.aqie.security.demo.response;

import lombok.Data;

import java.io.Serializable;

/**
 * @Function:
 * @Author: aqie
 * @Date: 2019/4/5 11:44
 */
@Data
public class ResponseModel<M> implements Serializable {
    private int code;
    private String message;

    private M data;

    public ResponseModel() {
        code = 1;
        message = "ok";
    }

    public ResponseModel(M result) {
        this();
        this.data = result;
    }

    public static <M> ResponseModel<M> success() {
        return new ResponseModel<M>();
    }


    // 成功时调用
    public static <M> ResponseModel<M> success(M data) {
        return new ResponseModel<M>(data);
    }

    public static <M> ResponseModel<M> error(CodeMsg codeMsg){
        return new ResponseModel<M>(codeMsg);
    }

    private ResponseModel(CodeMsg codeMsg){
        if (codeMsg == null)
            return;
        this.code = codeMsg.getCode();
        this.message = codeMsg.getMsg();
    }
}
